<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form">
        <div>
          <a-steps :current="current">
            <a-step v-for="item in steps" :key="item.title" :title="item.title">
              <a-icon slot="icon" :type="item.iconType" />
              <span style="color:#00DB00;" slot="description">{{item.description}}</span>
            </a-step>
          </a-steps>
          <div class="steps-content" style="" >
            <template   >
              <a-col :sm="12" v-show="current == 0" style="width:1000px">
                <!-- <j-dict-select-tag  type="radio" @change="onChangeType" v-model="type" dictCode="work_flow_type" placeholder="请选择交收类型" />-->

                <label>
                  <a-tag color="#f50" style="font-weight: bold;font-size: 16px;margin-left: 184px">
                    入库类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="1" v-model="type"> 公司购金</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="2" v-model="type"> 客户来金</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="3" v-model="type"> 金回库</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="4" v-model="type"> 盘点回金</label>
                  <br/>
                  <a-tag color="#2db7f5" style="font-weight: bold;font-size: 16px;margin-left: 55px">
                    出库类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="5" v-model="type"> 公司卖金</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="6" v-model="type"> 退客金</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="7" v-model="type"> 金出库</label>
                  <br/>
                  <a-tag color="#87d068" style="font-weight: bold;font-size: 16px;">
                    其他类：
                  </a-tag>
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="8" v-model="type"> 仓库调拨</label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <label style="font-weight: bold;font-size: 18px"><input type="radio" @change="onChangeType" name="type" value="9" v-model="type"> 员工金移交</label>

                </label>
              </a-col>
            </template>
            <template>
              <a-col v-show="current == 1 && this.type == 1" style="padding-left: 200px;padding-top: 60px;">
                <a-form-model-item label="发出客户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendCustomer">
                  <!-- <j-tree-select
                     style="width: 300px;margin-left: -300px"
                     v-model="sendCustomer"
                     dict="customer_info,cus_name,id,cus_type like '%,1,%' or cus_type like '%,2,%' or cus_type like '%,3,%' or cus_type like '%,4,%' order by create_time"
                     pid-field="pid"
                     pid-value="0"
                     onSearch="true">
                   </j-tree-select>-->
                  <j-dict-select-tag ref="sendCustomer" style="width: 300px;margin-left: -300px;font-size:16px"  @change="onChangeSendInfo(3)" v-model="sendCustomer" placeholder="请选择发出客户" dictCode="customer_info,cus_name,id"/>
                </a-form-model-item>
              </a-col>
              <a-col v-show="current == 1 && this.type == 2" style="padding-left: 200px;padding-top: 60px">
                <a-form-model-item label="发出客户"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendCustomer">

                  <j-dict-select-tag ref="sendCustomer" style="width: 300px;margin-left: -300px;font-size:16px"
                                     @change="onChangeSendInfo(3)" v-model="sendCustomer" placeholder="请选择发出客户"
                                     dictCode="customer_info,cus_name,id"/>
                </a-form-model-item>
              </a-col>
              <a-col v-show="current == 1 && (this.type == 3 || this.type == 4 ||this.type == 9)" style="padding-left: 200px;padding-top: 60px">
                <a-form-model-item label="发出员工"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendPerson">
                  <j-select-user-by-dep @change="onChangeSendInfo(1)"  style="width: 200px;margin-left: 10px;font-size:16px" ref="sendPerson" placeholder="请选择发出员工" :multi="false" v-model="sendPerson"/>
                </a-form-model-item>
              </a-col>
              <a-col v-show="current == 1 && (this.type == 5 || this.type == 6 || this.type == 7 || this.type == 8)" style="padding-left: 100px;padding-top: 60px">
                <a-form-model-item label="发出仓库"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendStorage">
                  <j-dict-select-tag @change="onChangeSendInfo(2)" ref="sendStorage" v-model="sendStorage" style="width: 300px;margin-left: -400px;font-size:16px" placeholder="请选择发出仓库" dictCode="gold_storage,name,id"/>
                </a-form-model-item>
              </a-col>
            </template>
            <template >
              <a-col v-show="current == 2 && (this.type == 1 || this.type == 2 || this.type == 3 || this.type == 4 || this.type == 8)" style="padding-left: 100px;padding-top: 60px">
                <a-form-model-item label="接收仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveStorage">
                  <j-dict-select-tag @change="onChangeReceiveInfo(2)" ref="receiveStorage" v-model="receiveStorage" style="width: 300px;margin-left: -400px;font-size:16px" placeholder="请选择接收仓库" dictCode="gold_storage,name,id"/>
                </a-form-model-item>
              </a-col>

              <a-col v-show="current == 2 && (this.type == 5 || this.type == 6)">
                <a-form-model-item style="padding-left: 200px;padding-top: 40px" label="接收客户"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveCustomer">
                  <j-dict-select-tag ref="receiveCustomer" style="width: 300px;margin-left: -300px"  @change="onChangeReceiveInfo(3)" v-model="receiveCustomer" placeholder="请选择接收客户" dictCode="customer_info,cus_name,id"/>

                </a-form-model-item>
              </a-col>

              <a-col v-show="current == 2 && (this.type == 7 || this.type == 9)" style="padding-left: 200px;padding-top: 60px">
                <a-form-model-item label="接收员工"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivePerson">
                  <j-select-user-by-dep @change="onChangeReceiveInfo(1)" style="width: 200px;margin-left: 10px" placeholder="请选择接收员工" :multi="false" v-model="receivePerson"/>
                </a-form-model-item>
              </a-col>

            </template>
            <template >
              <div v-show="current == 3">
                <j-editable-table
                  ref="editableTable"
                  :loading="loading"
                  :columns="columns"
                  :dataSource="dataSource"
                  :rowNumber="true"
                  :rowSelection="showRowSelection"
                  :actionButton="showActionButton"
                  :dragSort="showDragSort"
                  :scroll="{x:true,y:true}"
                  style="margin: 2px 2px 3px 3px"
                  @valueChange="handleValueChange"
                  @selectRowChange="handleSelectRowChange">

                  <template v-slot:action="props">
                    <a @click="handleDelete(props)">删除</a>
                  </template>
                  <template slot="picSlot" slot-scope="text, record">
                    <span v-for="(item,index) in (text|| '').split(',')">
                      <span v-if="item">
                        <img  :src="getImgView(item)" :preview="item" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
                        <a-divider type="vertical" />
                      </span>
                      <span v-else style="font-size: 12px;font-style: italic;">无图片</span>
                    </span>
                  </template>
                </j-editable-table>
              </div>

              <div>{{tips}}</div>
            </template>
          </div>
          <div class="steps-action">
            <a-button :disabled="current == 0" @click="prev">
              上一步
            </a-button>
            <!--<a-button style="margin-left: 8px"
              v-if="current == steps.length - 1"
              type="primary"
              @click="$message.success('完成!')"
            >
              完成
            </a-button>-->
            <a-button :disabled="current == (steps.length - 1)" ref="nextBtn" style="margin-left: 8px" type="primary" @click="next">
              下一步
            </a-button>
          </div>
        </div>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>
<script>
import moment from 'moment'
import { getAction, postAction } from '@/api/manage'
import { FormTypes } from '@/utils/JEditableTableUtil'
import { randomUUID, randomNumber } from '@/utils/util'
import JEditableTable from '@/components/jeecg/JEditableTable'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
import JTreeSelect from '@/components/jeecg/JTreeSelect'

export default {
  components: { JEditableTable,JSelectDepart,JTreeSelect },
  data() {
    return {
      title: '金出入库',
      width:1200,
      visible: false,
      confirmLoading: false,
      tips:'',
      form1: this.$form.createForm(this),
      current: 0,
      steps: [
        {
          title: '操作类型',
          content: 'First-content',
          iconType: 'appstore',
          description: ''
        },
        {
          title: '发出方',
          content: 'Second-content',
          iconType: 'user-delete',
          description: ''
        },
        {
          title: '接收方',
          content: 'Third-content',
          iconType: 'user-add',
          description: ''
        },
        {
          title: '确认',
          content: 'Fourth-content',
          iconType: 'form',
          description: ''
        }
        // {
        //   title: '完成',
        //  content: 'Last-content',
        //  iconType: 'check'
        //  },
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      showRowSelection: true,
      showActionButton: true,
      showDragSort: true,
      type: '',
      sendPerson: '',
      sendStorage: '',
      sendCustomer: '',
      receivePerson: '',
      receiveStorage: '',
      receiveCustomer: '',
      sendByName:'',//提示语
      receiveByName:'',//提示语
      loading: false,
      columns: [
        {
          title: '工单号',
          key: 'workNum',
          width: '100px',
          type: FormTypes.input,
        },
        {
          title: '订单号',
          key: 'orderCodeNum',
          width: '100px',
          type: FormTypes.input,
        },{
          title: '拆分页',
          key: 'pn',
          width: '70px',
          type: FormTypes.input,
          disabled:true
        },{
          title: '款号',
          key: 'styleCodeNum',
          width: '100px',
          type: FormTypes.input,
          //dictCode:'working_order,style_code_num,id',
          disabled: true,
        },{
          title: '成色*',
          key: 'karat',
          width: '100px',
          type: FormTypes.select,
          dictCode:'gold_karat,gold_karat_name,id',
        },{
          title: '来料名称',
          key: 'name',
          width: '80px',
          type: FormTypes.input,
        },{
          title: '种类',
          key: 'cate',
          width: '80px',
          type: FormTypes.select,
          dictCode:'gold_type'
        },{
          title: '规格',
          key: 'style',
          width: '80px',
          type: FormTypes.input,
        },{
          title: '数量',
          key: 'count',
          width: '60px',
          type: FormTypes.input,
        },{
          title: '连石重*',
          key: 'withStoneWeight',
          width: '80px',
          type: FormTypes.input,
        },{
          title: '石重(ct)',
          key: 'pureStoneWeight',
          width: '80px',
          type: FormTypes.input,
        },{
          title: '净重',
          key: 'goldWeight',
          width: '80px',
          type: FormTypes.input
        },{
          title: '不计耗重',
          key: 'noAttritionWeight',
          width: '80px',
          type: FormTypes.input
        },{
          title: '耗率(%)',
          key: 'attritionRate',
          width: '80px',
          type: FormTypes.input,
        },{
          title: '给耗重',
          key: 'giveAttrition',
          width: '80px',
          type: FormTypes.input,
          disabled: true
        },{
          title: '工费',
          key: 'procedureUnitPrice',
          width: '80px',
          type: FormTypes.input
        },{
          title: '折足率(%)',
          key: 'goldContent',
          width: '100px',
          type: FormTypes.input
        },{
          title: '折足重',
          key: 'goldContentWeight',
          width: '80px',
          type: FormTypes.input
        },{
          title: '单价',
          key: 'unitPrice',
          width: '80px',
          type: FormTypes.input
        },{
          title: '价值金额',
          key: 'costAmount',
          width: '80px',
          type: FormTypes.input,
          disabled: true
        },{
          title: '备注',
          key: 'remark',
          width: '100px',
          type: FormTypes.input
        }
      ],
      dataSource: [],
      selectedRowIds: [],
      url: {
        getPerson : "/goldEntry/getPerson",
        getStorage : "/goldEntry/getStorage",
        getCustomer : "/goldEntry/getCustomer"
      }
    };
  },
  computed: {
  },
  mounted() {
    // this.initData(false)
  },
  //自动触发点击事件
  watch:{
    type(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    sendPerson(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    sendCustomer(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    sendStorage(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    receivePerson(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    receiveCustomer(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    },
    receiveStorage(newVal,oldVal){
      if(newVal !='' && newVal !== oldVal) {
        this.$refs.nextBtn.$emit('click')
      }
    }
  },
  methods: {
    initStorageData(url,params) {//初始化仓库库存数据
      this.showRowSelection = true
      this.showActionButton = false
      this.showDragSort = false
      let that = this
      getAction(url,params).then((res)=>{
        if(res.success){
          let size = res.result.length
          let values = []
          for (let i = 0; i < size; i++) {
            if(res.result[i].count == 0 && res.result[i].withStoneWeight == 0
              && res.result[i].pureStoneWeight == 0 && res.result[i].goldWeight == 0) {
              continue
            }
            let idStr = randomUUID()
            values.push(
              {
                id: idStr,
                workNum: '',
                orderCodeNum: '',
                pn: '',
                styleCodeNum: '',
                karat: res.result[i].karat,
                name: '',
                cate: res.result[i].cate,
                style: res.result[i].style,
                count: res.result[i].count,
                withStoneWeight: res.result[i].withStoneWeight,
                pureStoneWeight: res.result[i].pureStoneWeight,
                goldWeight: res.result[i].goldWeight,
                noAttritionWeight: '',
                attritionRate: '',
                giveAttrition: '',
                procedureUnitPrice: '',
                goldContent: res.result[i].goldContent,
                goldContentWeight: res.result[i].goldContentWeight,
                unitPrice: '',
                costAmount: res.result[i].costAmount,
                remark: ''
              }
            )
          }
          that.dataSource = values
        }else{
          that.$message.warning(res.message);
        }
      })
    },
    getFormFieldValue(field){
      return this.form1.getFieldValue(field)
    },
    next() {
      if(this.current == 0) {
        if(this.type == '') {
          this.$message.warning('请先选择操作类型！');
          return
        }
        this.current++;
      }
      if(this.current == "1") {//发出方
        if(this.type == 1 || this.type == 2){//发出方是客户
          if(this.sendCustomer == null || this.sendCustomer == ''){
            //this.$message.warning('请选择发出客户')
            return
          }
          this.current++;
        } else if (this.type == 3 || this.type == 4 || this.type == 9) {//发出方是员工
          if(this.sendPerson == null || this.sendPerson == ''){
            //this.$message.warning('请选择发出员工')
            return
          }
          this.current++;
        } else if (this.type == 5 || this.type == 6 || this.type == 7 || this.type == 8) {//发出方是仓库
          if(this.sendStorage == null || this.sendStorage == ''){
            //this.$message.warning('请选择发出仓库')
            return
          }
          this.current++;
        }
      }else if(this.current == "2") {//接收方
        if (this.type == 1 || this.type == 2 || this.type == 3 || this.type == 4 || this.type == 8) {//接收仓库
          if(this.receiveStorage == null || this.receiveStorage == ''){
            //this.$message.warning('请选择接收仓库')
            return
          }
          this.current++;
        } else if (this.type == 5 || this.type == 6) {//接收客户
          if(this.receiveCustomer == null || this.receiveCustomer == ''){
            //this.$message.warning('请选择接收客户')
            return
          }
          this.current++;
        } else if (this.type == 7 || this.type == 9) {//接收员工
          if(this.receivePerson == null || this.receivePerson == ''){
            //this.$message.warning('请选择接收员工')
            return
          }
          this.current++;
        }
      }
      if(this.current == "3") {//确认
        if(this.type == 5 || this.type == 6 || this.type == 7 || this.type == 8){//当进行跟库存数据有关的操作类型时，要将库存数据列表显示出来
          let params = {
            storageId: this.sendStorage
          }
          this.initStorageData("/goldEntry/queryStorageData",params)
        } else if(this.type == 3 || this.type == 4 || this.type == 9){//员工移交金，库存在员工身上
          let params = {
            userId: this.sendPerson
          }
          this.initStorageData("/goldEntry/queryPersonData",params)
        }
      }
    },
    prev() {
      this.current--;
    },
    init () {
      this.visible = true
    },
    handleValueChange(event) {
      const { type, row, column, value, target } = event
      if (type === FormTypes.input) {
        if (column.key == 'workNum') {
          target.setValues([{
            rowKey: row.id,
            values: { workNum: value}
          }])
          if(value != null && value != '' && value.length>=4){
            let params = {
              workNum : value
            }
            getAction("/workingOrder/queryByWorknum",params).then(res=>{
              if(res.success){
                target.setValues([{
                  rowKey: row.id,
                  values: { orderCodeNum: res.result.orderCodeNum}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { pn: res.result.pn}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { styleCodeNum: res.result.styleCodeNum}
                }])
                target.setValues([{
                  rowKey: row.id,
                  values: { karat: res.result.karat}
                }])
                if(res.result.goldContent != null && res.result.goldContent != '') {
                  target.setValues([{
                    rowKey: row.id,
                    values: { goldContent: res.result.goldContent}
                  }])
                }
              }
            })
          }
        } else if (column.key == 'withStoneWeight') {
          target.setValues([{
            rowKey: row.id,
            values: { withStoneWeight: value}
          }])
        } else if (column.key == 'pureStoneWeight') {
          target.setValues([{
            rowKey: row.id,
            values: { pureStoneWeight: value}
          }])
        } else if (column.key == 'noAttritionWeight') {
          target.setValues([{
            rowKey: row.id,
            values: { noAttritionWeight: value}
          }])
        } else if (column.key == 'attritionRate') {
          target.setValues([{
            rowKey: row.id,
            values: { attritionRate: value}
          }])
        } else if (column.key == 'count') {
          target.setValues([{
            rowKey: row.id,
            values: { count: value}
          }])
        } else if (column.key == 'unitPrice') {
          target.setValues([{
            rowKey: row.id,
            values: { unitPrice: value}
          }])
        }  else if (column.key == 'goldWeight') {
          target.setValues([{
            rowKey: row.id,
            values: { goldWeight: value}
          }])
        } else {
          return
        }
      } else if (type === FormTypes.select) {
        if (column.key == 'karat') {
          target.setValues([{
            rowKey: row.id,
            values: { karat: value}
          }])
          if(value != null && value != '' ) {
            let params = {
              karat: value
            }
            getAction("/goldEntry/getGoldContentByKaratId",params).then(res=>{
              if(res.success){
                target.setValues([{
                  rowKey: row.id,
                  values: { goldContent: res.result}
                }])
              }
            })
          }
        } else {
          return
        }
      }
      //净金重计算
      let goldWeightVal = (row.withStoneWeight - row.pureStoneWeight*0.2).toFixed(2)
      target.setValues([{
        rowKey: row.id,
        values: { goldWeight: goldWeightVal }
      }])
      //给耗重计算
      let giveAttritionVal = ((goldWeightVal - row.noAttritionWeight) * row.attritionRate / 100).toFixed(2)
      target.setValues([{
        rowKey: row.id,
        values: { giveAttrition: giveAttritionVal}
      }])
      //折足重计算
      let goldContentWeightVal = (row.goldContent * goldWeightVal / 100).toFixed(2)
      target.setValues([{
        rowKey: row.id,
        values: { goldContentWeight: goldContentWeightVal}
      }])
      //价值金额计算
      let costAmountVal = (row.unitPrice * goldWeightVal).toFixed(2)
      target.setValues([{
        rowKey: row.id,
        values: { costAmount: costAmountVal }
      }])
    },
    onChangeSendInfo(type) {
      if(type == 1){//发出类型是员工
        if(this.sendPerson == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          username: this.sendPerson
        }
        getAction(this.url.getPerson,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      } else if (type == 2) {//发出类型是仓库
        if(this.sendStorage == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          id: this.sendStorage
        }
        getAction(this.url.getStorage,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      } else if (type == 3) {//发出类型是客户
        if(this.sendCustomer == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          id: this.sendCustomer
        }
        getAction(this.url.getCustomer,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      }
    },
    onChangeReceiveInfo(type) {
      if(type == 1){//接收类型是员工
        if(this.receivePerson == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          username: this.receivePerson
        }
        getAction(this.url.getPerson,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      } else if (type == 2) {//接收类型是仓库
        if(this.receiveStorage == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          id: this.receiveStorage
        }
        getAction(this.url.getStorage,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      } else if (type == 3) {//接收类型是客户
        if(this.receiveCustomer == ''){
          this.steps[this.current].description = ''
          return
        }
        let params = {
          id: this.receiveCustomer
        }
        getAction(this.url.getCustomer,params).then((res)=>{
          if(res.success){
            this.steps[this.current - 1].description = res.result
          }
        })
      }
    },
    onChangeType () {
      this.showActionButton = true
      this.steps[1].description = ''
      this.steps[2].description = ''
      this.sendPerson = ''
      this.sendStorage = ''
      this.sendCustomer = ''
      this.receivePerson = ''
      this.receiveStorage = ''
      if(this.type == 1) {//公司购金
        this.steps[0].description = '公司购金'
      } else if(this.type == 2) {//客来金
        this.steps[0].description = '客来金'
      } else if(this.type == 3) {//金回库
        this.steps[0].description = '金回库'
      } else if(this.type == 4) {//盘点回金
        this.steps[0].description = '盘点回金'
      } else if(this.type == 5) {//公司卖金
        this.steps[0].description = '公司卖金'
      } else if(this.type == 6) {//退客金
        this.steps[0].description = '退客金'
      } else if(this.type == 7) {//金出库
        this.steps[0].description = '金出库'
      } else if(this.type == 8) {//仓库调拨
        this.steps[0].description = '仓库调拨'
      } else if(this.type == 9) {//员工金移交
        this.steps[0].description = '员工金移交'
      }
    },
    close () {
      this.confirmLoading = false;
      this.$emit('ok')
      this.$refs.form.clearValidate()
      this.$refs.form.resetFields()
      Object.assign(this.$data, this.$options.data.call(this))
      this.visible = false
    },
    handleOk () {
      const that = this
      // 触发表单验证
      // this.$refs.form.validate(valid => {
      // if (valid) {
      //     that.confirmLoading = true;
      //    }
      //  });
      this.handleTableGet()
    },
    handleCancel () {
      this.close()
    },
    /** 表单验证 */
    handleTableCheck() {
      this.$refs.editableTable.getValues((error) => {
        if (error === 0) {
          this.$message.success('验证通过')
        } else {
          this.$message.error('验证未通过')
        }
      })
    },
    /** 获取值，忽略表单验证 */
    handleTableGet() {
      this.$refs.editableTable.getValues((error, values) => {
        console.log('values:', values)
        let params = {
          sendPerson: this.sendPerson,
          sendStorage: this.sendStorage,
          sendCustomer: this.sendCustomer,
          receivePerson: this.receivePerson,
          receiveStorage: this.receiveStorage,
          receiveCustomer: this.receiveCustomer,
          type: this.type,
          data : values
        }
        postAction("/goldEntry/batchAdd",params).then(res=>{
          if(res.success){
            this.$message.success(res.message)
            this.close()
          }else{
            this.$message.error(res.message)
          }
        })
      }, false, this.selectedRowIds)
      //console.log('deleteIds:', this.$refs.editableTable.getDeleteIds())

      //this.$message.info('获取值成功，请看控制台输出')

    },
    /** 模拟加载1000条数据 */
    handleTableSet() {
      this.randomData(1000, true)
    },
    handleSelectRowChange(selectedRowIds) {
      this.selectedRowIds = selectedRowIds
      /*this.dataSource.forEach((row) => {
        let rowId = row.id
        let index = this.selectedRowIds.indexOf(rowId)
        this.columns.forEach((column) => {
          if(index == -1) {
            column.disabled = true
          } else {
            column.disabled = false
          }
        });
      })*/
    },
    /* 随机生成数据 */
    randomData(size, loading = false) {
      if (loading) {
        this.loading = true
      }
      let randomDatetime = () => {
        let time = parseInt(randomNumber(1000, 9999999999999))
        return moment(new Date(time)).format('YYYY-MM-DD HH:mm:ss')
      }
      let begin = Date.now()
      let values = []
      for (let i = 0; i < size; i++) {
        values.push({
          id: randomUUID(),
          dbFieldName: `name_${i + 1}`,
          // dbFieldTxt: randomString(10),
          multipleSelect: ['string', ['int', 'double', 'boolean'][randomNumber(0, 2)]],
          dbFieldType: ['string', 'int', 'double', 'boolean'][randomNumber(0, 3)],
          dbLength: randomNumber(0, 233),
          datetime: randomDatetime(),
          isNull: ['Y', 'N'][randomNumber(0, 1)]
        })
      }
      this.dataSource = values
      let end = Date.now()
      let diff = end - begin

      if (loading && diff < size) {
        setTimeout(() => {
          this.loading = false
        }, size - diff)
      }
    },
    handleDelete(props) {
      let { rowId, target } = props
      target.removeRows(rowId)
    }
  },
};
</script>
<style scoped>
.steps-content {
  margin-top: 16px;
  border: 1px dashed #aaaaaa;
  border-radius: 6px;
  background-color: #fafafa;
  min-height: 300px;
  text-align: center;
  padding-top: 20px;
}

.steps-action {
  margin-top: 24px;
}
</style>